import {
  BeforeInsert,
  BeforeUpdate,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity('services')
export class Service {
  @PrimaryGeneratedColumn({
    name: 'service_id',
    type: 'int',
    comment: '主键 id',
  })
  serviceId: number;

  @Column({
    name: 'account_name',
    type: 'varchar',
    length: 25,
    comment: 'UPYUN 账号名',
  })
  accountName: string;

  @Column({
    name: 'sell_id',
    type: 'int',
    comment: 'UPYUN 账号所属销售id',
  })
  sellId: number;

  @Column({
    name: 'storage_total',
    type: 'bigint',
    comment: '已用存储',
  })
  storageTotal: number;

  @Column({
    name: 'flow_day_average',
    type: 'decimal',
    default: 0.0,
    comment: '日均流量',
  })
  flowDayAverage: string;

  @Column({
    name: 'flow_day_peak',
    type: 'decimal',
    default: 0.0,
    comment: '',
  })
  flowDayPeak: string;

  @Column({
    name: 'account_status',
    type: 'varchar',
    length: 20,
    comment: '账号状态 便于状态搜索',
  })
  accountStatus: string;

  @CreateDateColumn({
    name: 'created_at',
    comment: '创建时间',
  })
  createdAt: Date;

  @UpdateDateColumn({
    name: 'updated_at',
    comment: '更新时间',
  })
  updatedAt: Date;

  @Column({
    name: 'important',
    type: 'int',
    comment: '重要度 1:A 2:B 3:C 4:D',
  })
  important: number;

  @Column({
    name: 'bill_month_average',
    type: 'decimal',
    default: 0.0,
    comment: '月均消费',
  })
  billMonthAverage: string;

  @Column({
    name: 'bill_total',
    type: 'decimal',
    default: 0.0,
    comment: '消费总量',
  })
  billTotal: string;

  @Column({
    name: 'flow_left',
    type: 'bigint',
    comment: '剩余可用流量(GB)',
  })
  flowLeft: number;

  @Column({
    name: 'flow_yestoday',
    type: 'bigint',
    comment: '',
  })
  flowYestoday: number;

  @Column({
    name: 'scale',
    type: 'float',
    comment: '等级',
  })
  scale: string;

  @Column({
    name: 'days_last_mon_200mb',
    type: 'int',
    default: 0,
    comment: '',
  })
  daysLastMon200mb: number;

  @Column({
    name: 'days_this_mon_200mb',
    type: 'int',
    default: 0,
    comment: '',
  })
  daysThisMon200mb: number;

  @Column({
    name: 'first_buy_time',
    type: 'bigint',
    default: 0,
    comment: '首次购买时间',
  })
  firstBuyTime: number;

  @Column({
    name: 'call_type',
    type: 'varchar',
    length: 20,
    comment: '用户类型',
  })
  callType: string;

  @Column({
    name: 'buy_type',
    type: 'varchar',
    length: 20,
    comment: '购买类型',
  })
  buyType: string;

  @Column({
    name: 'company',
    type: 'varchar',
    length: 15,
    comment: '公司',
  })
  company: string;

  @Column({
    name: 'allotted_at',
    type: 'int',
    comment: '最后分配销售时间',
  })
  allottedAt: number;

  @Column({
    name: 'coupon_remain',
    type: 'decimal',
    comment: '代金券余额',
  })
  couponRemain: string;

  // @BeforeInsert()
  // private updateCreatedAt() {
  //   this.createdAt = Math.ceil(Date.now() / 1000);
  // }

  // @BeforeUpdate()
  // private updateUpdatedAt() {
  //   this.updatedAt = Math.ceil(Date.now() / 1000);
  // }
}
